package com.ruoyi.purchase.service.impl;

import com.ruoyi.purchase.domain.OrderDetail;
import com.ruoyi.purchase.domain.RawProductDetail;
import com.ruoyi.purchase.domain.SupplyDetail;
import com.ruoyi.purchase.mapper.RawProductDetailMapper;
import com.ruoyi.purchase.service.IRawProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * RawProductDetailService业务层处理
 * 
 * @author kevinness
 * @date 2025-01-18
 */
@Service
public class RawProductDetailService implements IRawProductDetailService
{
    @Autowired
    private RawProductDetailMapper rawProductDetailMapper;

    /**
     * 查询RawProductDetail
     *
     * @param rawProductCode RawProductDetail主键
     * @return RawProductDetail
     */
    @Override
    public RawProductDetail selectRawProductDetailByRawProductCode(String rawProductCode)
    {
        return rawProductDetailMapper.selectRawProductDetailByRawProductCode(rawProductCode);
    }

    /**
     * 根据订单详情查询剩余带调拨数量
     *
     * @param orderDetail
     * @return 剩余数量
     */
    @Override
    public int getRemainAllocationQuantityByOrderDetail(OrderDetail orderDetail){
        return rawProductDetailMapper.getRemainAllocationQuantityByOrderDetail(orderDetail);
    }

    /**
     * 查询RawProductDetail列表
     *
     * @param rawProductDetail RawProductDetail
     * @return RawProductDetail
     */
    @Override
    public List<RawProductDetail> selectRawProductDetailList(RawProductDetail rawProductDetail)
    {
        return rawProductDetailMapper.selectRawProductDetailList(rawProductDetail);
    }

    /**
     * 新增RawProductDetail
     *
     * @param rawProductDetail RawProductDetail
     * @return 结果
     */
    @Override
    public int insertRawProductDetail(RawProductDetail rawProductDetail)
    {
        return rawProductDetailMapper.insertRawProductDetail(rawProductDetail);
    }

    /**
     * 修改RawProductDetail
     *
     * @param rawProductDetail RawProductDetail
     * @return 结果
     */
    @Override
    public int updateRawProductDetail(RawProductDetail rawProductDetail)
    {
        return rawProductDetailMapper.updateRawProductDetail(rawProductDetail);
    }

    /**
     * 批量删除RawProductDetail
     *
     * @param rawProductCodes 需要删除的RawProductDetail主键
     * @return 结果
     */
    @Override
    public int deleteRawProductDetailByRawProductCodes(String[] rawProductCodes)
    {
        return rawProductDetailMapper.deleteRawProductDetailByRawProductCodes(rawProductCodes);
    }

    /**
     * 删除RawProductDetail信息
     *
     * @param rawProductCode RawProductDetail主键
     * @return 结果
     */
    @Override
    public int deleteRawProductDetailByRawProductCode(String rawProductCode)
    {
        return rawProductDetailMapper.deleteRawProductDetailByRawProductCode(rawProductCode);
    }

    /**
     * 使用货源详情查询货品详细信息
     *
     * @param supplyDetail
     * @return 每个货品详细信息数组
     */
    @Override
    public List<RawProductDetail> selectRawProductDetailListBySupplyDetail(SupplyDetail supplyDetail){
        return rawProductDetailMapper.selectRawProductDetailListBySupplyDetail(supplyDetail);
    }

    /**
     * 根据订单编号获取每个货品的信息
     *
     * @param orderNo 订单编号
     * @return 每个货品详细信息列表
     */
    @Override
    public List<RawProductDetail> selectRawProductDetailListByOrderNo(String orderNo){
        RawProductDetail rawProductDetail = new RawProductDetail();
        rawProductDetail.setOrderNo(orderNo);
        rawProductDetail.setAllocationStatus("未分配");
        return selectRawProductDetailList(rawProductDetail);
    }
}
